package com.liguo.whoisthespy.ui

import android.app.Activity
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.liguo.whoisthespy.R
import kotlinx.android.synthetic.main.ppw_look_over.view.*
import kotlinx.android.synthetic.main.ppw_write_iyrics.view.*
import org.jetbrains.anko.onClick
import org.jetbrains.anko.toast

/**
 * 查看词语
 * Created by su on 2017/6/17.
 */
class WriteIyricsPpw(val act: PhaseActivity): PopupWindow() {
    private val pupView by lazy{
        (act.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
                .inflate(R.layout.ppw_write_iyrics,null)
    }

    init {
        //设置SelectPicPopupWindow的View
        this.contentView = pupView
        //设置SelectPicPopupWindow弹出窗体的宽
        this.width = ViewGroup.LayoutParams.MATCH_PARENT
        //设置SelectPicPopupWindow弹出窗体的高
        this.height = ViewGroup.LayoutParams.MATCH_PARENT
        //设置SelectPicPopupWindow弹出窗体可点击
        this.isFocusable = true
        setBackgroundDrawable(ColorDrawable(0x00000000))

        contentView.apply {
            ppw_wi_layout.onClick { dismiss() }
            ppw_wi_context_layout.onClick {  }
            ppw_wi_quxiao.onClick { dismiss() }
            ppw_wi_queding.onClick {
                val p = ppw_wi_pingmin.text.toString().trim()
                val w = ppw_wi_wodi.text.toString().trim()
                if(p.isEmpty()){
                    act.toast("平民词不能为空")
                    return@onClick
                }
                if(w.isEmpty()){
                    act.toast("卧底词不能为空")
                    return@onClick
                }
                act.startPlay(p,w)
                dismiss()
            }
        }
    }

    fun show(parent: View?) {
        showAtLocation(parent, Gravity.BOTTOM, 0,0)
    }
}
